fix: set default maxRetries to 0 for OpenAI endpoint to prevent retry delays (fixes #12547)#12666
Draft
armorbreak001 wants to merge 1 commit intodanny-avila:mainfrom
Draft
Conversation
danny-avila
requested changes
Apr 15, 2026
| /** Default to 0 retries to avoid long delays from LangChain's | ||
| * exponential backoff (up to ~2 min with default maxRetries=6). | ||
| * Can be overridden via modelOptions or customParams.defaultParams. */ | ||
| maxRetries: 0, |
Owner
There was a problem hiding this comment.
This would only resolve #12547 if you made it configurable
Author
|
Thanks for the review @danny-avila! To clarify: Settings → Endpoints → [endpoint] → Advanced → Custom Parameters → defaultParams: {
"maxRetries": 3
}The code flow is:
So the user can configure That said, I'm happy to make the default itself configurable (e.g., via env var) if you'd prefer. Let me know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
When an OpenAI-compatible API returns an error (e.g., 503), LangChain's AsyncCaller retries up to 6 times with exponential backoff, causing a ~2 minute delay before the user sees the error message. This happens because the default
maxRetriesin@langchain/coreis 6.While
@librechat/agentsalready setsmaxRetries: 0on the OpenAI SDK client itself, the outer LangChain layer still retries viacaller.call(...).Solution
Set
maxRetries: 0as the default in the OpenAI LLM configuration. This disables the outer LangChain retry layer by default, so error responses are returned immediately to the user.The value can still be overridden:
modelOptions.maxRetriesin conversation settingscustomParams.defaultParamswith{ key: "maxRetries", default: N }Changes
packages/api/src/endpoints/openai/llm.ts: AddedmaxRetries: 0to the default llmConfig object ingetOpenAILLMConfig(). SinceObject.assignis used, any explicitmaxRetriesvalue frommodelOptionsordefaultParamswill override this default.Verification
maxRetries: 2in model options → verify retries still work as expectedCloses #12547